import axios from 'axios';
import router from '@/router';
// axios的二次封装
import { getCookie } from '@/utils/auth.js'
let service = axios.create({
    // 基本地址
    baseURL: 'http://8.136.129.225:3000/api',
    timeout: 5000
});

// 请求拦截器
service.interceptors.request.use(config => {
    let token = getCookie();
    console.log(token);
    // 放到请求头部中发送给后台
    config.headers["hg_token"] = token;
    return config;
})

// 响应拦截器(一般是http状态码的管理)

service.interceptors.response.use(response => {
    let status = response.data.status;
    switch (status) {
        case 200:
            return response
        case 1001:
        case 1002:
        case 1003:
        case 1004:
        case 1005:
            return response
        case 10010:
        case 10011:
        case 401:
            router.push('/login')
            break
        default:
            break

    }
})





export default service;